package com.xingchi.tornado.dict.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xingchi.tornado.dict.model.domain.DictDO;
import com.xingchi.tornado.dict.model.dto.DictDTO;
import com.xingchi.tornado.dict.model.dto.DictQueryDTO;
import com.xingchi.tornado.dict.mapper.DictMapper;
import com.xingchi.tornado.dict.service.DictService;
import com.xingchi.tornado.mybatisplus.service.AbstractBasePlusService;
import com.xingchi.tornado.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xingchi
 * @date 2024-05-20 22:34
 */
@Service
public class DictServiceImpl extends AbstractBasePlusService<DictMapper, DictDTO, DictQueryDTO, DictDO> implements DictService {

    @Autowired
    private DictMapper dictMapper;

    @Override
    public Wrapper<DictDO> getWrapper(DictQueryDTO query) {
        return Wrappers.<DictDO>lambdaQuery()
                .eq(StringUtils.isNotBlank(query.getGroup()), DictDO::getGroup, query.getGroup());
    }

    /**
     * 批量插入字典数据
     *
     * @param dictList 字典数据
     */
    @Override
    public void saveBatch(List<DictDTO> dictList) {
        List<DictDO> dictDOS = BeanUtils.copyList(dictList, DictDO.class);
        this.saveBatch(dictDOS);
    }
}
